<template>
    <h2>增加房号</h2>
    <input type="button" value="房号展示" @click="okkmkwsa">
    <table>
        <tr>
            <td>房号</td>
            <td>
                <input type="text" v-model="poien.name">
            </td>
        </tr>
        <tr>
            <td>房间类型</td>
            <td>
                <select v-model="poien.typeid">
                    <option value="">请选择</option>
                    <option :value="pi.roomID" v-for="pi in fxlist">{{ pi.rname }}</option>
                </select>
            </td>
        </tr>
        <tr>
            <td>房态</td>
            <td>
                <select v-model="poien.statid">
                    <option value="">请选择</option>
                    <option :value="iopw.sid" v-for="iopw in ftlist">{{ iopw.statename }}</option>
                </select>
            </td>
        </tr>
        <tr>
            <td>备注</td>
            <td>
                <textarea cols="30" rows="3" v-model="poien.desc"></textarea>
            </td>
        </tr>
        <tr>
            <td></td>
            <td>
                <input type="button" value="添加" @click="ownnkws">
            </td>
        </tr>
    </table>
  </template>
  
  <script setup lang="ts">
  import {onMounted, reactive, toRefs} from 'vue'
  import {useRouter,useRoute} from 'vue-router'
  import axios from 'axios'
  const router=useRouter()
  const route=useRoute()

  let data:any=reactive({
    poien:{
        name:'',
        typeid:'',
        statid:'',
        desc:''
    },
    fxlist:[],
    ftlist:[]
  })
  let {poien,ftlist,fxlist} =toRefs(data)

  onMounted(()=>{
    gettype()
    getstates()
  })

  const gettype:any=()=>{
    axios({
        url:'/api/Room/Bindtype',
        method:'get'
    })
    .then(res=>{
        fxlist.value=res.data.data;
    })
  }

  const getstates:any=()=>{
    axios({
        url:'/api/Room/Bindstates',
        method:'get'
    })
    .then(res=>{
        ftlist.value=res.data.data;
    })
  }

  const ownnkws=()=>{
    let obj={
        "nname": poien.value.name,
  "rid": poien.value.typeid,
  "stateid": poien.value.statid,
  "desc": poien.value.desc,
  "nstates": 1,
  "isDelete": false
    }
    axios({
        url:'/api/Room/Addnum',
        method:'post',
        data:obj
    })
    .then(res=>{
        if(res.data.data==1){
            alert("添加房号成功")
            router.push('shownum')
        }else if(res.data.data==-2){
            alert("房号不能重复")
        }else{
            alert("添加房号失败")
        }
    })
  }

  const okkmkwsa=()=>{
    router.push('shownum')
  }
  </script>
  
  <style scoped>
  
  </style>